There are some table we would like to include in the latex document, but we first have to format them to meet the requirements. Specifically, these are the tables of significant disease enrichment results.


In [1]:
cd ../../HBP/


/home/gavin/Documents/MRes/HBP

In [2]:
import csv

In [9]:
import numpy as np

In [66]:
from pylab import *

In [3]:
ls


communityDetection.C@         Makefile@         README@
communityDetection.OpenMP.C@  node.h@           run@
data/                         nr3.h@            testdata/
edge.h@                       OUT/              unweightedOUT/
eigen_sym.h@                  OUTW/             unweighted_significant_disease_communities.tsv@
enrichmentStudies.h@          protounweighted/  unweighted_significant_SCH_communities.tsv@
Headers.h@                    protoweighted/    weighted_significant_disease_communities.tsv@
Helper.h@                     ran.h@            weighted_significant_SCH_communities.tsv@
ludcmp.h@                     readInputFile.h@

In [7]:
with open("unweighted_significant_disease_communities.tsv") as f:
    c = csv.reader(f,delimiter="\t")
    tabstrings = list(c)

In [19]:
t = tabstrings[1][3]

In [67]:
def texSI(t):
    t = "{:.2e}".format(float(t))
    t = t.split("e")
    t = r"$" + t[0] + r"\e{" + t[1] + r"}" + "$"
    return t

In [85]:
with open("unweighted_significant_disease_communities.tex","w") as f:
    for i,l in enumerate(tabstrings):
        if i==0:
            f.write(" ".join([r" & ".join(l[:4]+[l[-2]]), r"\\", "\n"]))
        else:
            l = l[:3] + map(texSI,l[3:6]) + l[6:]
            f.write(" ".join([r" & ".join(l[:4]+[l[-2]]), r"\\", "\n"]))

In [86]:
!head unweighted_significant_disease_communities.tex


Community & Size & disease & p-value & p_lower (%) \\ 
29 & 88 & schizophrenia & $1.69\e{-03}$ & 0.2 \\ 
2 & 99 & schizophrenia & $4.32\e{-03}$ & 0.5 \\ 
30 & 26 & Alzheimer's_disease & $5.37\e{-03}$ & 0.7 \\ 
61 & 24 & schizophrenia & $1.96\e{-02}$ & 1.5 \\ 
63 & 23 & Alzheimer's_disease & $3.50\e{-02}$ & 4.3 \\ 
61 & 24 & Alzheimer's_disease & $4.25\e{-02}$ & 4.5 \\ 
63 & 23 & schizophrenia & $4.62\e{-02}$ & 4.3 \\ 

In [87]:
with open("weighted_significant_disease_communities.tsv") as f:
    c = csv.reader(f,delimiter="\t")
    tabstrings = list(c)

In [88]:
with open("weighted_significant_disease_communities.tex","w") as f:
    for i,l in enumerate(tabstrings):
        if i==0:
            f.write(" ".join([r" & ".join(l[:4]+[l[-2]]), r"\\", "\n"]))
        else:
            l = l[:3] + map(texSI,l[3:6]) + l[6:]
            f.write(" ".join([r" & ".join(l[:4]+[l[-2]]), r"\\", "\n"]))